<template>
  <div class="transparent-header">
    <div class="mask" :style="{backgroundColor: color, opacity: opacity}"></div>
    <div class="page-header-con">
      <div class="back-btn" @click="pageBack"></div>
      <div class="opt-btn-wrap">
        <div class="refresh-btn" @click="pageRefresh"></div>
        <div class="close-btn" @click="pageClose"></div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "TransparentHeader",
  props: {
    color: {
      type: String,
      default: '#FFFFFF'
    },
    scrollHeight: {
      type: Number,
      default: 200
    },
    pageTitle: {
      default: window.document.title
    }
  },
  data() {
    return {
      opacity: 0,
    }
  },
  mounted() {
    window.addEventListener('scroll', this.changeOpacity, true )
  },
  destroyed() {
    window.removeEventListener('scroll', this.changeOpacity, true )
  },
  methods: {
    changeOpacity() {
      let wait = 100
      if (!this.timeout) {
        this.timeout = setTimeout(() => {
          this.timeout = null;
          let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
          this.opacity = scrollTop/this.scrollHeight < 1 ? scrollTop/this.scrollHeight : 1
        }, wait)
      }
    },
    pageBack() {
      this.$emit('pageBack')
    },
    pageRefresh() {
      this.$emit('pageRefresh')
    },
    pageClose() {
      this.$emit('pageClose')
    }
  }
}
</script>

<style scoped lang="less">
.transparent-header {
  width: 100vw;
  height: 160px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;

  /*background-color: #892cfe;*/
  .mask {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
  }
  .page-header-con {
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding: 60px 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .back-btn {
    width: 60px;
    height: 60px;
    background-image: url('./img/free_icon_back.png');
    background-size: 60px 60px;
  }
  .title {
    margin: 0 auto;
  }

  .opt-btn-wrap {
    padding: 0 9px;
    width: 160px;
    height: 60px;
    background: rgba(0,0,0,.2);
    border-radius: 30px;
    display: flex;
    justify-content: space-between;
    position: relative;
    &:after {
      content: '';
      display: block;
      width: 1px;
      height: 20px;
      background: rgba(255, 255, 255, .5);
      position: absolute;
      top: 20px;
      left: 80px;
    }

    .refresh-btn {
      width: 60px;
      height: 60px;
      background-image: url('./img/free_icon_Refresh.png');
      background-size: 60px 60px;
    }
    .close-btn {
      width: 60px;
      height: 60px;
      background-image: url('./img/free_icon_close.png');
      background-size: 60px 60px;
    }
  }
}
</style>
